//
//  XHInfoDetailViewController.m
//  xidian
//
//  Created by 冷山 on 16/5/20.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHInfoDetailViewController.h"

#import "Services.h"
#import <DateTools/DateTools.h>

@interface XHInfoDetailViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *ui_webView;
@property (strong, nonatomic) NSDictionary * m_newsDic;
@end

@implementation XHInfoDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadNewsData];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)loadNewsData{
    [ServiceManager getNewsDetailWithId:self.m_newsId success:^(NSDictionary *data) {
        self.m_newsDic=data;
        [self updateView];
    } failure:^(NSDictionary *data) {
        
    }];
}

- (void)updateView{
    NSDate *date=[NSDate dateWithString:self.m_newsDic[@"recDate"]];
    NSString *releaseTime=[date formattedDateWithFormat:@"yyyy.MM.dd"];
    NSMutableString *htmlString=[NSMutableString string];
    [htmlString appendFormat:@"<h1 style=' font-size:17pt; color:#000000; font-weight:normal; padding-top:20pt; padding-bottom:0pt; padding-left:10pt;'>%@</h1>",self.m_newsDic[@"contentTitle"]];
    [htmlString appendFormat:@"<h3 style='font-size:13pt; color:#858585; font-weight:normal; line-height:10pt; padding-top:0pt; padding-bottom:0pt; padding-left:10pt;'>%@</h3><hr />",releaseTime];
    [htmlString appendString:self.m_newsDic[@"contentBody"]];
    [self.ui_webView loadHTMLString:htmlString baseURL:nil];
}
@end
